/*
 *  ChasingAI.cpp
 *  
 *
 *  Created by Nicholas Blecha on 11/15/10.
 *  Copyright 2010 Michigan Technological University. All rights reserved.
 *
 */

#include "chasingAI.h"
#include <math.h>
#include <iostream>

ChasingAI::ChasingAI(Renderer* rend, Logic* lgc) : Fighter(10, 30, 10) {
	rnd = rend;
	logic = lgc;
	initializeBeams();
	image = rnd->loadImage("Images//drone1.png");
	texId = rnd->createTexture(image);
	position.x = 500;
	position.y = 600;
	position.w = image->w;
	position.h = image->h;
	
	countToNextShot=15;
	
	drawPos->w=image->w;
	drawPos->h=image->h;
	
	defaultColor=BLUE;
	
	target=NULL;
}

void ChasingAI::decide(int choice) {
	if (target!=NULL) {
		int extrapolateX;
		if (fabs(cos(angle+M_PI/2))<0.001) {
			extrapolateX = position.x;
		} else 
			extrapolateX = (int) ((target->getRect()->y - position.y)/cos(angle+M_PI/2)*sin(angle+M_PI/2));
		cout << extrapolateX << endl;
		bool furtherLeftThanTarget = extrapolateX>target->getRect()->x;
		bool belowTarget = target->getRect()->y < position.y;
		if (furtherLeftThanTarget!=belowTarget) {
			turnRight();
		} else {
			turnLeft();
		}
	}
	accelerateForward();
	if (countToNextShot<=0) {
		normal->fire();
		countToNextShot=15*choice;
	} else {
		countToNextShot--;
	}

}